package com.clkj.nangang.app;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.clkj.nangang.BuildConfig;
import com.clkj.nangang.R;
import com.clkj.nangang.common.Config;
import com.clkj.nangang.http.HttpService;
import com.clkj.nangang.util.LogUtil;
import com.clkj.nangang.util.PicassoImageLoader;
import com.clkj.nangang.util.Res;
import com.clkj.nangang.util.viewutil.PicassoPauseOnScrollListener;

import cn.finalteam.galleryfinal.CoreConfig;
import cn.finalteam.galleryfinal.FunctionConfig;
import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.ImageLoader;
import cn.finalteam.galleryfinal.ThemeConfig;


/**
 * Created by Administrator on 2017/6/20.
 */

public class CustomApplication extends Application {


    public static Context globeContext;
    private static CustomApplication mInstance;

    public static CustomApplication getInstance() {
        return mInstance;
    }


    private HttpService mHttpService;

    private HttpService mHttpWorkService;

    public HttpService getHttpService() {
        if (mHttpService == null) {
            mHttpService = HttpService.Factory.create(Config.URL_BASE_IN_USE);
        }
        return mHttpService;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        globeContext = this;
        //initHttpService();
        initLog();
        initGalleyFinal();
    }

    private void initGalleyFinal() {
        //设置主题
        //ThemeConfig.CYAN
        ThemeConfig theme = new ThemeConfig.Builder()
                .setTitleBarBgColor(Res.getColor(R.color.wechat_black))
                .setTitleBarTextColor(Res.getColor(R.color.white))
                .setTitleBarIconColor(Res.getColor(R.color.white))
                .setFabNornalColor(Res.getColor(R.color.wechat_black))
                .setFabPressedColor(Res.getColor(R.color.wechat_black_dark))
                .setCheckSelectedColor(Res.getColor(R.color.wechat_black))
                .build();


        //配置功能
        FunctionConfig functionConfig = new FunctionConfig.Builder()
                .setEnableCamera(true)
                .setEnableEdit(true)
                .setEnableCrop(true)
                .setEnableRotate(true)
                .setCropSquare(true)
                .setEnablePreview(true)
                .build();
       /* FunctionConfig functionConfig = new FunctionConfig.Builder()
                .setEnableCamera(true)
                .setEnablePreview(true)
                .build();*/


        //配置imageloader
        ImageLoader imageloader = new PicassoImageLoader();

        CoreConfig coreConfig = new CoreConfig.Builder(this, imageloader, theme)
                .setFunctionConfig(functionConfig)
                .setPauseOnScrollListener(new PicassoPauseOnScrollListener(false, true))
                .build();
        GalleryFinal.init(coreConfig);
    }

    private void initHttpService() {
        mHttpService = HttpService.Factory.create("");
    }

    private void initLog() {
        LogUtil.isDebug = BuildConfig.DEBUG;
    }

}
